package com.company;

public class IPChecker {


    public boolean checkIp(String str) {
        if (str == null) {
            return false;
        }
        //判断是否 .分割
        if (!str.contains(".")) {
            return false;
        }
        String[] split = str.split("\\.");
        if (split.length != 4) {
            return false;
        }
        //判断每段是否 数字
        for (int i = 0; i < split.length; i++) {
            String num = split[i];
            try {
                int ipNum = Integer.parseInt(num);
                if (ipNum < 0 || ipNum > 255) {
                    return false;
                }

            } catch (NumberFormatException e) {
                e.printStackTrace();
                return false;
            }

        }
        return true;
    }

    /*
     *                     A
     *                  p
     *            l   p
     *         a
     *
     *
     * */
}
